package code08_三大特征;

/*
 * 英雄类
 */
public class Hero {
	private String name; // 英雄名称
	private int blood; // 生命值
	private int attack; // 攻击力
	private int defend; // 防御力
	private Skill skill; // 掌握的技能

	// 构造方法
	public Hero() {
		super();
	}

	public Hero(String name, int blood, int attack, int defend, Skill skill) {
		super();
		this.name = name;
		this.blood = blood;
		this.attack = attack;
		this.defend = defend;
		this.skill = skill;
	}

	// getter/setter方法
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getBlood() {
		return blood;
	}

	public void setBlood(int blood) {
		this.blood = blood;
	}

	public int getAttack() {
		return attack;
	}

	public void setAttack(int attack) {
		this.attack = attack;
	}

	public int getDefend() {
		return defend;
	}

	public void setDefend(int defend) {
		this.defend = defend;
	}

	public Skill getSkill() {
		return skill;
	}

	public void setSkill(Skill skill) {
		this.skill = skill;
	}
	
	/*
	 * 学习新技能
	 */
	public void study(Skill skill) {
		if(skill.getLevel() > this.skill.getLevel()) {
			this.skill = skill;
		}else {
			System.out.println(skill.getName()+"等级过低，不需要学习！");
		}
	}
	
	/*
	 * 攻击
	 */
	public void attack() {
		System.out.println("英雄"+name+"正在展开攻击");
		System.out.println("当前生命值为："+blood);
		System.out.println("攻击力为："+(attack+skill.getAttack()));
	}
	
	/*
	 * 防御
	 */
	public void defend(int attack) {
		if(attack < (defend+skill.getDefend())) {
			System.out.println("防御成功！");
			System.out.println("英雄"+name+"正以"+(defend+skill.getDefend())+"防御力抵御了攻击！");
			System.out.println("当前生命值为："+blood);
		}else {
			System.out.println("防御失败！");
			System.out.println("英雄"+name+"正以"+(defend+skill.getDefend())+"防御力未能抵御攻击！");
			System.out.println("当前生命值为："+(blood-attack));
		}
	}
	

}
